'zegar claas
$EEPROM
Data 0 , 0 , 0 , 0 
$DATA
$regfile "attiny2313.dat"
$crystal = 4000000

Dim Dziegodz As Byte , Jedgodz As Byte , Dziemin As Byte , Jedmin As Byte , Sekundy As Byte , Sek As Bit ,
Dim Dziegodz1 As Byte , Jedgodz1 As Byte , Minuty As Byte , Tysgodz1 As Byte , Setgodz1 As Byte , Sekundy1 As Byte
Dim 100ms As Byte , Ktorywysw As Byte , Licz As Bit , Licz1 As Bit , 100ams As Byte
Config Portb = 255 : Portb = &B11111111 : Config Portd = &B0111100 : Portd = &B1111111
Config Timer0 = Timer , Prescale = 64 : Enable Interrupts : Enable Timer0
On Timer0 Co4ms

Dziegodz = 0 : Jedgodz = 0 : Dziemin = 0 : Jedmin = 0
100ms = 0
Licz1 = 1

Readeeprom Jedgodz1 , 1
Readeeprom Dziegodz1 , 2
Readeeprom Setgodz1 , 3
Readeeprom Tysgodz1 , 4

Do
Debounce Pind.1 , 0 , Wl , Sub
Debounce Pind.0 , 0 , Zero , Sub
Debounce Pind.6 , 0 , Mth , Sub
Loop
End


Co4ms:
Timer0 = 6
Incr 100ams
   If 100ams = 2 Then                                       ' powinno byc 250
      100ams = 0
Incr Sekundy1
      If Sekundy1 = 60 Then
         Sekundy1 = 0
         Incr Minuty
         If Minuty = 60 Then
            Minuty = 0
            Incr Jedgodz1
            If Jedgodz1 = 9 Then
               Jedgodz1 = 0
               Incr Dziegodz1
               If Dziegodz1 = 9 Then
                  Dziegodz1 = 0
                  Incr Setgodz1
                  If Setgodz1 = 9 Then
                     Setgodz1 = 0
                     Incr Tysgodz1
                     If Tysgodz1 = 9 Then
                        Tysgodz1 = 0
                     End If
               End If
         End If
      End If
   End If
End If
End If

If Licz = 1 Then
   Incr 100ms
   If 100ms = 2 Then                                        ' powinno byc 250
      100ms = 0 : Toggle Sek
      Incr Sekundy
      If Sekundy = 60 Then
         Sekundy = 0
         Incr Jedmin
         If Jedmin = 10 Then
            Jedmin = 0
            Incr Dziemin
            If Dziemin = 6 Then
            Dziemin = 0
            Incr Jedgodz
               If Jedgodz = 10 Then
                  Jedgodz = 0
                  Incr Dziegodz
                     If Dziegodz = 9 Then Dziegodz = 0
               End If
         End If
      End If
   End If
End If
End If



Incr Ktorywysw
   If Ktorywysw = 4 Then Ktorywysw = 0
   Portd = &B1111111
If Licz1 = 1 Then
Select Case Ktorywysw
   Case 0:
      Portb = Lookup(jedgodz1 , Tabela)
      Portd.2 = 0
   Case 1:
      Portb = Lookup(dziegodz1 , Tabela)
      Portd.3 = 0
   Case 2:
      Portb = Lookup(setgodz1 , Tabela)
      Portd.4 = 0
   Case 3:
      Portb = Lookup(tysgodz1 , Tabela)
      Portd.5 = 0
End Select
Else
Select Case Ktorywysw
   Case 0:
      Portb = Lookup(jedmin , Tabela)
      Portd.2 = 0
   Case 1:
      Portb = Lookup(dziemin , Tabela)
      Portd.3 = 0
   Case 2:
      Portb = Lookup(jedgodz , Tabela)
      Portd.4 = 0
      If Licz = 0 Then                                      ' jezeli odliczanie wylaczone to
         Portb.7 = 0                                        'zapal na stale kropki pomiedzy minutami i godzinami
            Else                                            ' jezeli odliczanie wlaczone to
               Portb.7 = Sek                                'migaj kropkami pomiedzy minutami i godzinami co sekunde
      End If
   Case 3:
      Portb = Lookup(dziegodz , Tabela)
      Portd.5 = 0
End Select
End If
Return

Wl:
Toggle Licz
Return

Zero:
If Licz = 0 Then
Dziegodz = 0 : Jedgodz = 0 : Dziemin = 0 : Jedmin = 0
End If
Writeeeprom Jedgodz1 , 1
Writeeeprom Dziegodz1 , 2
Writeeeprom Setgodz1 , 3
Writeeeprom Tysgodz1 , 4
Return

Mth:
Toggle Licz1
Return

Tabela:
Data 192 , 249 , 164 , 176 , 153 , 146 , 130 , 248 , 128 , 144


